/**
 * @program: data_structures_algorithms
 * @description: 反转单链表
 * @author: lld
 * @create: 2020/08/16 15:22
 **/
public class Demo2 {
    public static void main(String[] args) {
        ListNode listNode=new ListNode(1, new ListNode(2, new ListNode(4, new ListNode(3, null))));
        System.out.println("反转后的链表");
        System.out.println(reverseList(listNode));
    }

    public static ListNode reverseList(ListNode head){
        if(head==null){
            return null;
        }
        ListNode pre =null;
        ListNode cur=head;
        ListNode temp=null;
        while(cur!=null){
            temp=cur.next;
            cur.next=pre;
            pre=cur;
            cur=temp;
        }
        return pre;
    }
}




